﻿<Page x:Class="WinKee.Pages.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:Converters="using:WinKee.Converters"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
      mc:Ignorable="d">
    <Page.Resources>
        <Converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter" />
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Command="{Binding SelectDatabaseCommand}"
                              Label="Pick a DB"
                              Visibility="{Binding IsPickFileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="OpenFile" />
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Command="{Binding AddKeyfileCommand}"
                              Label="Add a KF"
                              Visibility="{Binding IsAddKeyfileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Permissions" />
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Command="{Binding RemoveKeyfileCommand}"
                              Label="Remove KF"
                              Visibility="{Binding IsRemoveKeyfileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Clear" />
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Command="{Binding OpenCommand}"
                              Label="Decrypt"
                              Visibility="{Binding IsUnlockVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Accept" />
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Command="{Binding CancelCommand}"
                              Label="Cancel"
                              Visibility="{Binding IsCancelVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Cancel" />
                    </AppBarButton.Icon>
                </AppBarButton>
            </CommandBar.PrimaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <StackPanel Orientation="Vertical">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="MainGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0">
                        <VisualTransition.GeneratedEasingFunction>
                            <BackEase EasingMode="EaseIn" />
                        </VisualTransition.GeneratedEasingFunction>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="PickerState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                       
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock2" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock3" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock5" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock8" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="FileOpenStatePass">
                    <Storyboard>
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock5" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock7" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="FileOpenStateText">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock5" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock7" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="DecryptingState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock2" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock3" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock7" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel Margin="12,17,12,28">
            <TextBlock Style="{ThemeResource TitleTextBlockStyle}"
                       Text="WinKee"
                       Typography.Capitals="SmallCaps" />
            <TextBlock Margin="0,12,0,0"
                       Style="{ThemeResource HeaderTextBlockStyle}"
                       Text="open file" />
        </StackPanel>
        <ScrollViewer>
            <StackPanel
                        Margin="12,0"
                        Orientation="Vertical">

                <TextBlock x:Name="textBlock7" Style="{StaticResource BodyTextBlockStyle}">
                    <Run Text="Pick a database to open by pressing the 'Pick a DB' button below." />
                </TextBlock>

                <ListView x:Name="listView"
                          MaxHeight="100"
                          IsItemClickEnabled="True"
                          ItemClick="RecentFiles_OnItemClick"
                          ItemsSource="{Binding RecentFiles}"
                          SelectionMode="None">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Foreground="{StaticResource PhoneAccentBrush}"
                                       Style="{StaticResource BodyTextBlockStyle}"
                                       Text="{Binding Item2}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

                <TextBlock x:Name="textBlock4"
                           Foreground="{StaticResource PhoneAccentBrush}"
                           Style="{StaticResource GroupHeaderTextBlockStyle}">
                    <Run Text="Decrypting database..." />
                </TextBlock>
                <TextBlock x:Name="textBlock5"
                           Style="{StaticResource BodyTextBlockStyle}"
                           TextWrapping="Wrap">
                    <Run Text="This might take a lot of time, depending on the value of the &quot;Number of key transformation rounds&quot; setting in the database and the size of the database." />
                </TextBlock>

                <TextBlock x:Name="textBlock8"
                           Style="{StaticResource BodyTextBlockStyle}"
                           Text="Estimated time to derive the decryption key is "
                           TextWrapping="Wrap" />
                <StackPanel x:Name="stackPanel" Orientation="Horizontal">
                    <TextBlock Margin="0,0,6,0"
                               Foreground="{StaticResource PhoneAccentBrush}"
                               Style="{StaticResource BodyTextBlockStyle}"
                               Text="{Binding EstimatedOpeningTime}" />
                    <TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="seconds" />
                </StackPanel>

                <PasswordBox x:Name="PasswordBox"
                             Header="Password"
                             KeyDown="PasswordBox_OnKeyDown"
                             Password="{Binding Password,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" IsPasswordRevealButtonEnabled="True" />
               
                

                <TextBlock x:Name="textBlock2"
                           FontSize="24"
                           Foreground="{StaticResource PhoneAccentBrush}"
                           Text="{Binding KeyfileName}"
                           TextTrimming="CharacterEllipsis"
                           TextWrapping="Wrap"
                           Visibility="{Binding KeyfileName,
                                                Converter={StaticResource EmptyStringToVisibilityConverter}}" />
                <TextBlock x:Name="textBlock3"
                           FontSize="16"
                           Text="{Binding KeyfilePath}"
                           TextTrimming="CharacterEllipsis"
                           Visibility="{Binding KeyfilePath,
                                                Converter={StaticResource EmptyStringToVisibilityConverter}}" />
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
</Page>
